<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// add include_once(APPPATH.'core/'.'MY_Controller.php'); in System/Core/Loader : function _ci_autoloader

class MY_Controller extends CI_Controller
{
	protected $data = array();
	function __construct()
	{
		parent::__construct();
		include "./common/admin/access.php";
		$this->data["siteName"] = $siteName;
		$this->data["lang"] = $lang;
		$this->data["langDB"] = $langDB;
		$this->data["language"] = $language;
		$this->data["arr_lang"] = $arr_lang;
		$this->data["arr_visible"] = $arr_visible;
		$this->data["arr_yesno"] = $arr_yesno;
		$this->data["homepage"] = $homepage;
		$this->data["siteTitle"] = $lang[$this->data["menu"]]["title"];
		$this->data["pageTitle"] = $this->data["siteTitle"];
		$this->data["paging_value"] = !empty($paging_value) ? $paging_value : 10;

		//form fields
		$this->data["arr_fields_category"] = $arr_fields_category;
		$this->data["arr_fields_news"] = $arr_fields_news;
		$this->data["arr_lang_chk_empty"] = $arr_lang_chk_empty;
		$this->data["arr_fields_product"] = $arr_fields_product;
		$this->data["arr_fields_setting"] = $arr_fields_setting;		
		
		//path
		$this->data["product_dir"] = $product_dir;
		$this->data["product_path"] = $product_path;
		$this->data["news_dir"] = $news_dir;
		$this->data["news_path"] = $news_path;
		
		//site_setting
		$site_setting = $this->settingModel->get_setting($arr_lang);
		$this->data = array_merge($this->data, $site_setting);		
		$site_setting = $this->settingModel->get_settingLan(array("lan" => $language, "code" => $site_setting["code"]));
		$this->data = array_merge($this->data, $site_setting);	
		
		//image
		$this->data["image_width"] = $image_width;
		$this->data["image_height"] = $image_height;
		$this->data["image_width_list"] = $image_width_list;
		$this->data["image_height_list"] = $image_height_list;
		
		$this->data["head"] = render(APPPATH . "views/admin/head.php", $this->data);
		$this->data["header"] = render(APPPATH . "views/admin/header.php", $this->data);
		$this->data["menu"] = render(APPPATH . "views/admin/menu.php", $this->data);
		$this->data["footer"] = render(APPPATH . "views/admin/footer.php", $this->data);
	}
}

class MY_FrontController extends CI_Controller
{
	protected $data = array();
	function __construct()
	{
		parent::__construct();
		include "./common/access.php";
		$this->data["siteName"] = $siteName;
		$this->data["lang"] = $lang;
		$this->data["langDB"] = $langDB;
		$this->data["language"] = $language;
		$this->data["arr_lang"] = $arr_lang;
		$this->data["arr_visible"] = $arr_visible;
		$this->data["arr_yesno"] = $arr_yesno;
		$this->data["homepage"] = $homepage;
		$this->data["paging_value"] = !empty($paging_value) ? $paging_value : 10;

		//form fields
		$this->data["arr_fields_category"] = $arr_fields_category;
		$this->data["arr_fields_news"] = $arr_fields_news;
		$this->data["arr_lang_chk_empty"] = $arr_lang_chk_empty;
		$this->data["arr_fields_product"] = $arr_fields_product;
		$this->data["arr_fields_setting"] = $arr_fields_setting;		
		
		//path
		$this->data["product_dir"] = $product_dir;
		$this->data["product_path"] = $product_path;
		$this->data["news_dir"] = $news_dir;
		$this->data["news_path"] = $news_path;
		
		//image
		$this->data["image_width"] = $image_width;
		$this->data["image_height"] = $image_height;
		$this->data["image_width_list"] = $image_width_list;
		$this->data["image_height_list"] = $image_height_list;
		
		//site_setting
		$site_setting = $this->settingModel->get_setting($arr_lang);
		$this->data = array_merge($this->data, $site_setting);		
		$site_setting = $this->settingModel->get_settingLan(array("lan" => $language, "code" => $site_setting["code"]));
		$this->data = array_merge($this->data, $site_setting);		
		
		//header links
		$this->data["header_link"] = $header_link;
		
		$this->data["website"] = $website;
		
		//paging
		$page = !empty($_GET["page"]) ? $_GET["page"] : "";
		$page = intval($page);
		if($page < 1)
			$page = 1;
		$this->data["page"] = $page;
		$this->data["news_paging_value"] = $news_paging_value;
		$this->data["product_paging_value"] = $product_paging_value;		
		
		$this->data["menu_active"] = "home";
		$this->data["category_active"] = "";
		$this->data["category_list"] = $this->categoryModel->get_all(0, 0, "position", array("lan" => $language, "visible" => "y"));	
		
		//uri plus
		$uri_plus = "";
		for($i=0; $i<6; $i++){
			$str = $this->uri->segment($i);
			if(!empty($str))
				$uri_plus .= "," . $str;
		}
		$this->data["uri_plus"] = $uri_plus;
	}
    
    function get_link()
    {
		$menu_link = "";
		$active = "";
		if($this->data["menu_active"] == "home")
			$active = "class=\"active\"";
		$menu_link .= "<li><a {$active} href=\"" . base . "\"><span>" . $this->data["lang"]["navi"]["home"] . "</span></a></li>\n";
		
		$active = "";
		if($this->data["menu_active"] == "intro")
			$active = "class=\"active\"";
        $menu_link .= "<li><a {$active} href=\"".base_index . stripUnicode($this->data["lang"]["navi"]["intro"])."\"><span>" . $this->data["lang"]["navi"]["intro"] . "</span></a></li>\n";
		
		$active = "";
		if($this->data["menu_active"] == "product")
			$active = "class=\"active\"";
        $menu_link .= "<li><a {$active} href=\"".base_index . stripUnicode($this->data["lang"]["navi"]["product"])."\"><span>" . $this->data["lang"]["navi"]["product"] . "</span></a></li>\n";
		
		$active = "";
		if($this->data["menu_active"] == "news")
			$active = "class=\"active\"";
        $menu_link .= "<li><a {$active} href=\"".base_index . stripUnicode($this->data["lang"]["navi"]["news"])."\"><span>" . $this->data["lang"]["navi"]["news"] . "</span></a></li>\n";
		
		$active = "";
		if($this->data["menu_active"] == "contact")
			$active = "class=\"active\"";
        $menu_link .= "<li><a {$active} href=\"".base_index . stripUnicode($this->data["lang"]["navi"]["contact"])."\"><span>" . $this->data["lang"]["navi"]["contact"] . "</span></a></li>\n";    
		$this->data["menu_link"] = $menu_link;
		
		$this->data["head"] = render(APPPATH . "views/head.php", $this->data);
		$this->data["header"] = render(APPPATH . "views/header.php", $this->data);
		$this->data["left"] = render(APPPATH . "views/left.php", $this->data);
		$this->data["footer"] = render(APPPATH . "views/footer.php", $this->data);		
	}	
}